import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'layout', // 给布局路由一个名字
    component: () => import('@/layout/index.vue'),
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('@/views/home/index.vue'),
        meta: {
          title: '首页',
          isHide: false,
          isKeepAlive: true,
          roles: [],
          icon: 'i-mdi-home'
        }
      },
      {
        path: '/settings',
        name: 'settings',
        component: () => import('@/views/settings/index.vue'),
        meta: {
          title: '设置',
          isLink: false,
          isHide: false,
          isKeepAlive: true,
          isAffix: false,
          isIframe: false,
          roles: [],
          icon: 'i-mdi-cog'
        }
      },
      {
        path: '/chat',
        name: 'chat',
        component: () => import('@/views/chat/index.vue'),
        meta: {
          title: '聊天',
          isLink: false,
          isHide: false,
          isKeepAlive: true,
          isAffix: false,
          isIframe: false,
          roles: [],
          icon: 'i-mdi-chat'
        }
      },
      {
        path: '/401',
        name: 'noPower',
        component: () => import('@/views/error/401.vue'),
        meta: {
          title: '401',
          isHide: true
        }
      },
      {
        path: '/404',
        name: 'notFound',
        component: () => import('@/views/error/404.vue'),
        meta: {
          title: '404',
          isHide: true
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '登录'
    }
  },
  {
    path: '/logout', // 如果直接访问 /logout，会渲染登录页
    name: 'logout',
    component: () => import('@/views/login/index.vue'), // 按照您的要求
    meta: {
      title: '重新登录' // 稍微修改一下 title 以示区别
    }
  },
  // 通配符路由，匹配所有未定义的路径，并重定向到404页面
  // 确保这个路由在最后
  {
    path: '/:pathMatch(.*)*',
    name: 'catchAll',
    redirect: '/404'
  }
];

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL), // Electron 中常使用 Hash 模式
  routes
});

export default router;
